package com.swufe.lianxi;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.view.menu.BaseMenuPresenter;
import androidx.appcompat.view.menu.MenuPresenter;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.text.BreakIterator;

public class ScoreActivity extends AppCompatActivity implements View.OnClickListener {
    private static final String TAG = "TAG";
    TextView score_a;
    TextView score_b;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_score);
        score_a = (TextView) findViewById(R.id.score_a);
        score_b = (TextView) findViewById(R.id.score_b);
    }
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        String scorea = ((TextView)findViewById(R.id.score_a)).getText().toString();
        String scoreb = ((TextView)findViewById(R.id.score_b)).getText().toString();
        Log.i(TAG, "onSaveInstanceState: ");
        outState.putString("teama_score",scorea);
        outState.putString("teamb_score",scoreb);
    }
    @Override
    public void onClick(View v) {
        TextView txtName1 = (TextView) findViewById(R.id.txt1);
        TextView txtName2 = (TextView) findViewById(R.id.txt3);
        Button btn1 = findViewById(R.id.btn1);
        Button btn2 = findViewById(R.id.btn2);
        Button btn3 = findViewById(R.id.btn3);
        Button btn4 = findViewById(R.id.btn4);
        Button btn5 = findViewById(R.id.btn5);
        Button btn6 = findViewById(R.id.btn6);
        Button btn7 = findViewById(R.id.btn7);
        //设置监听器
        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);
        btn3.setOnClickListener(this);
        btn4.setOnClickListener(this);
        btn5.setOnClickListener(this);
        btn6.setOnClickListener(this);
        btn7.setOnClickListener(this);
    }
    public void btnAdd1(View btn){
    showscore_a(3);
    }
    public void btnAdd2(View btn){
    showscore_a(2);
    }
    public void btnAdd3(View btn){
    showscore_a(1);
    }
    public void btnAdd4(View btn){
        score_a.setText("0" );
        score_b.setText("0" );
    }
    public void btnAdd5(View btn){
     showscore_b(3);
    }
    public void btnAdd6(View btn){
     showscore_b(2);
    }
    public void btnAdd7(View btn){
    showscore_b(1);
    }
    private void showscore_a(int inc){
        Log.i("show","inc="+inc);
        String oldscore_a=(String)score_a.getText();
        int newScore_a=Integer.parseInt(oldscore_a)+inc;
        score_a.setText("" + newScore_a);
    }
    private void showscore_b(int inc){
        Log.i("show","inc="+inc);
        String oldscore_b=(String)score_b.getText();
        int newScore_b=Integer.parseInt(oldscore_b)+inc;
        score_b.setText("" + newScore_b);
    }
}